import { Injectable } from '@nestjs/common';
import { CreateUserRoleDto } from './dto/create-user-role.dto';
import { UpdateUserRoleDto } from './dto/update-user-role.dto';
import { DataSource, Repository } from 'typeorm';
import { UserRole } from './entities/user-role.entity';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class UserRoleService {
  constructor(
    @InjectRepository(UserRole)
    private readonly userRoleRepository: Repository<UserRole>,
    private readonly dataScoure: DataSource,
  ) {}
  create(createUserRoleDto: CreateUserRoleDto) {
    return 'This action adds a new userRole';
  }

  // 获取用户所书角色
  findUserOfRole(id) {
    let baseSql = `SELECT * FROM user_role_tb ur 
    LEFT JOIN user_tb u ON ur.user_id = u.user_id 
    LEFT JOIN role_tb r ON ur.role_id = r.role_id`
    baseSql += ` WHERE u.user_id = ${id}`
    return this.userRoleRepository.query(baseSql);
  }
}
